import Taro, { Component } from '@tarojs/taro'
import { View, Image, Text } from '@tarojs/components'

import './style.scss'

class WeekList extends Component {
  static defaultProps = {
    weekData: []
  }
  isNotANumber = num => {
    if (parseFloat(num).toString() === 'NaN') {
      return false
    } else {
      return true
    }
  }

  onOpen(data) {
    Taro.navigateTo({
      url: `/pages/anime/index?id=${data.id}`
    })
  }

  render() {
    const { weekData } = this.props
    return (
      <View className='week-list'>
        {weekData.map(item => (
          <View className='week-list__li' onClick={this.onOpen.bind(this, item)} key={item.id}>
            <View className='week-list__pic'>
              <Image className='week-list__pic__image' src={item.pic} mode='aspectFit' />
            </View>
            <Text className='week-list__title'>{item.title}</Text>
            <Text className={`week-list__text ${item.isDate ? 'week-list__text__red' : ''}`}>
              {this.isNotANumber(item.status) ? `更新至${item.status}话` : item.status}
            </Text>
          </View>
        ))}
      </View>
    )
  }
}

export default WeekList
